function binary_search(arr, low, high, key) {
    if (low > high) {
        return -1;
    }
    var mid = parseInt((low + high) / 2);
    if (arr[mid] === key) 
        return mid;
    else if (arr[mid] > key){
        high = mid - 1
        return binary_search(arr, low, high, key);
    }
    else if (arr[mid] < key) {
        low = mid + 1;
        return binary_search(arr, low , high, key);
    }
};


const sortedArr = [1, 3, 5, 7, 9, 11];
const key = 7;

const index = binary_search(sortedArr, 0, sortedArr.length - 1, key);
console.log(`元素 ${key} 的索引是：${index}`); 
